package com.rd.student.jike.class1.fangzhou;


import java.util.LinkedList;

public class LinkedListTest {
    //根据班级返回list
    public static LinkedList asBanji(String banji, LinkedList list) {
        LinkedList list1 = new LinkedList();
        for (int i = 0; i < list.size(); i++) {
            Group_Num gg = (Group_Num) (list.get(i));
            if (gg.getBanji() == banji) {
                list1.add(list.get(i));
            }
        }
        return list1;
    }

    //根据专业返回list
    public static LinkedList asMojor(String mojor, LinkedList list) {
        LinkedList list2 = new LinkedList();
        for (int i = 0; i < list.size(); i++) {
            Group_Num gg = (Group_Num) (list.get(i));
            if (gg.getMajor() == mojor) {
                list2.add(list.get(i));
            }
        }
        return list2;
    }

    //根据年龄返回list
    public static LinkedList asAge(int age, LinkedList list) {
        LinkedList list3 = new LinkedList();
        for (int i = 0; i < list.size(); i++) {
            Group_Num gg = (Group_Num) (list.get(i));
            if (gg.getAge() == age) {
                list3.add(list.get(i));
            }
        }
        return list3;
    }

    //成员名字汇总
    public static LinkedList getAllNum(LinkedList list) {
        LinkedList list4 = new LinkedList();
        for (int i = 0; i < list.size(); i++) {
            Group_Num gg = (Group_Num) (list.get(i));
            list4.add(gg.getName());
        }
        return list4;
    }
    //筛选年龄大于等于几岁的
    public static LinkedList bigAge(int age, LinkedList list) {
        LinkedList list5 = new LinkedList();
        for (int i = 0; i < list.size(); i++) {
            Group_Num gg = (Group_Num) (list.get(i));
            if (gg.getAge() >= age) {
                list5.add(list.get(i));
            }
        }
        return list5;
    }
    //计算平均年龄
    public static int eveAge(LinkedList list){
        int num = 0;
        for (int i = 0; i < list.size(); i++) {
            Group_Num gg = (Group_Num) (list.get(i));
            num+=gg.getAge();
        }
        return num/list.size();
    }
    //筛选年龄小于等于几岁的
    public static LinkedList smallAge(int age, LinkedList list) {
        LinkedList list6 = new LinkedList();
        for (int i = 0; i < list.size(); i++) {
            Group_Num gg = (Group_Num) (list.get(i));
            if (gg.getAge() <= age) {
                list6.add(list.get(i));
            }
        }
        return list6;
    }

    public static void main(String[] args) {
        LinkedList list = new LinkedList();
        Group_Num g1 = new Group_Num("高晨曦", "软件工程", "软件3班", 19, "帅");
        list.add(g1);
        Group_Num g2 = new Group_Num("张思韬", "软件工程", "软件3班", 18, "帅");
        list.add(g2);
        Group_Num g3 = new Group_Num("孙昊", "计算机与科学技术", "计科1班", 24, "帅");
        list.add(g3);
        Group_Num g4 = new Group_Num("方周", "计算机与科学技术", "计科1班", 26, "帅");
        list.add(g4);
        Group_Num g5 = new Group_Num("郭佳宝", "计算机与科学技术", "计科1班", 20, "傻");
        list.add(g5);
        Group_Num g6 = new Group_Num("姜万里", "计算机与科学技术", "计科1班", 8, "肥");
        list.add(g6);
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i).toString());
        }
        System.out.println("----------------------------------------------------------------");
        System.out.println(asBanji("计科1班", list));
        System.out.println("----------------------------------------------------------------");
        System.out.println(asMojor("软件工程", list));
        System.out.println("----------------------------------------------------------------");
        System.out.println(asAge(8, list));
        System.out.println("----------------------------------------------------------------");
        System.out.println(getAllNum(list));
        System.out.println("----------------------------------------------------------------");
        System.out.println(bigAge(21,list));
        System.out.println("----------------------------------------------------------------");
        System.out.println(smallAge(20,list));
        System.out.println("----------------------------------------------------------------");
        System.out.println("平均年龄为："+eveAge(list));
    }
}

    class Group_Num {
        private String name;
        private String major;
        private String banji;
        private int age;
        private String miaoshu;

        public Group_Num() {
        }

        public Group_Num(String name, String major, String banji, int age, String miaoshu) {
            this.banji = banji;
            this.major = major;
            this.name = name;
            this.age = age;
            this.miaoshu = miaoshu;
        }

        public String getBanji() {
            return banji;
        }

        public String getMajor() {
            return major;
        }

        public String getName() {
            return name;
        }

        public int getAge() {
            return age;
        }

        public String getMiaoshu() {
            return miaoshu;
        }

        public void setBanji(String banji) {
            this.banji = banji;
        }

        public void setMajor(String major) {
            this.major = major;
        }

        public void setName(String name) {
            this.name = name;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public void setMiaoshu(String miaoshu) {
            this.miaoshu = miaoshu;
        }

        @Override
        public String toString() {
            return "姓名：" + name + "   " +
                    "专业：" + major + "   " +
                    "班级：" + banji + "   " + "年龄：" + age + "   " + "描述：" + miaoshu;
        }
    }
